<?php
/**
 * Created by PhpStorm.
 * User: Lionel
 * Date: 2015/4/28
 * Time: 12:01
 */

namespace business\procurement\models;

use business\base\models\BaseActiveRecord;

/**
 * Class BiddingModel
 * @property string uid
 * @property string title
 * @property string shortTitle
 * @property string developerUid
 * @property int procurementType
 * @property int sourceType
 * @property int isSupportOnline
 * @property datetime registerEndDate
 * @property datetime auditTime
 * @property int operateState
 * @property int state
 * @property int isValid
 * @property int isDelete
 * @property string finalistBy
 * @property string finalistTime,
 * @property string sendbidBy
 * @property datetime sendbidTime
 * @property string winbidBy
 * @property datetime completeWinbidTime
 * @property string createdBy
 * @property datetime createdTime,
 * @property string lastModifiedBy
 * @property datetime lastModifiedTime
 * @property datetime auditTag
 * @property string erpBidId
 */
/**
 * Class BiddingModel
 * @property string uid
 * @property string title
 * @property string shortTitle
 * @property string developerUid
 * @property int procurementType
 * @property int purchaseMethod
 * @property int sourceType
 * @property int isSupportOnline
 * @property datetime registerEndDate
 * @property datetime auditTime
 * @property  string  belongCompanyName
 * @property  int  belongFrameworkId
 * @property int operateState
 * @property int state
 * @property int isValid
 * @property int isDelete

 * @property datetime completeWinbidTime
 * @property string createdBy
 * @property datetime createdTime,
 * @property string lastModifiedBy
 * @property datetime lastModifiedTime
 * @property datetime auditTag
 * @property string erpBidId
 * @property string isJumpSendbid
 * @property int create_type
 * @property  datetime winbidEfficientTime
 * @property  int is_need_complete_material  是否需要完善资料
 *
 * @property string   finalistBy   资格预审人
 * @property datetime finalistTime  资格预审时间
 * @property  string  sendbidBy   发标人
 * @property  datetime  sendbidTime  发标时间
 * @property  string  openBidBy  开标人
 * @property  datetime  openBidTime  开标时间
 * @property  string  evaluateBy  评标人
 * @property  datetime  evaluateTime  评标时间
 * @property  string  winbidBy    定标人
 * @property  datetime  winbidTime  定标时间
 */
class BiddingModel extends BaseActiveRecord
{
    const BIDDING_REGISTERING = "2";
    const BIDDING_REGISTER_END = "3";
    const BIDDING_ERROR = "4";
    const BIDDING_PRE_QUALIFY = "5";
    const BIDDING_SEND = "10";
    const BIDDING_RETURN = "100";
    const BIDDING_DISCUSS="300";
    const BIDDING_WIN = "500";



    /* @var  integer 操作状态 作废 */
    const OPERATE_STATE_OBSOLETE=5;
    /* @var  integer 操作状态 审核中 */
    const OPERATE_STATE_AUDIT_ING=1;
    /* @var  integer 操作状态 审核通过 */
    const OPERATE_STATE_AUDIT=2;


    /* @var integer 公开招标 */
    const  PROCUREMENT_TYPE_PUBLIC=0;

    /* @var integer 邀请招标 */
    const PROCUREMENT_TYPE_INVITE=1;

    public static function tableName()
    {
        return 'b2b_bidding.bid_announcements';
    }

    public $_fieldsAlias = [
        'uid' => 'uid',
        'title' => 'title',
        'shortTitle' => 'short_title',
        'developerUid' => 'developer_uid',
        'procurementType' => 'procurement_type',
        'belongCompanyName'=>'belong_company_name',
        'belongFrameworkId' => 'belong_framework_id',
        'purchaseMethod'=>'purchase_method',
        'sourceType' => 'source_type',
        'isSupportOnline' => 'is_support_online',
        'isPublishShow'=>'is_publish_show',
        'registerEndDate' => 'register_end_date',
        'auditTime' => 'audit_time',
        'operateState' => 'operate_state',
        'state' => 'state',
        'isValid' => 'is_valid',
        'isDelete' => 'is_delete',
        'completeWinbidTime' => 'complete_winbid_time',
        'createdBy' => 'created_by',
        'createdTime' => 'created_time',
        'lastModifiedBy' => 'last_modified_by',
        'lastModifiedTime' => 'last_modified_time',
        'auditTag'=> 'audit_tag',
        'erpBidId'=> 'erp_uid',
        'isJumpSendbid'=>'is_jump_sendbid',
        'winbidEfficientTime'=>'winbid_efficient_time',
        'finalistBy' => 'finalist_by',
        'finalistTime' => 'finalist_time',
        'sendbidBy' => 'sendbid_by',
        'sendbidTime' => 'sendbid_time',
        'openBidBy' =>'open_bid_by' ,
        'openBidTime' =>  'open_bid_time',
        'evaluateBy' => 'evaluate_by',
        'evaluateTime' => 'evaluate_time',
        'winbidBy' => 'winbid_by',
        'winbidTime' =>'winbid_time'

    ];

    /*
        public function rules()
        {
            return [
                // name, email, subject 和 body 属性必须有值
                ['belongCompanyName', 'required'],
                ['purchaseMethod','required'],
                ['procurementType','required']

                // email 属性必须是一个有效的电子邮箱地址
                ['email', 'email'],
            ];
        }

    */



    public $_id;
    //招标分类
    public $bidCategories;
    //项目所在地
    public $bidAreas;
    //招标项目
    public $bidProjects;
    //招标预告附属信息
    public $bidExpand;
    //招标报名条件
    public $bidCondition;
    //招标报名区域名字
    public $biddingAreaNames;
    //招标报名条件服务区域
    public $bidServiceAreas;
    //招标报名条件公司区域
    public $bidCompanyAreas;
    //招标报名条件服务资质
    public $bidServiceQualify;
    //招标相关文档
    public $bidDocuments;

    public  $biddingAreaName;
    public  $biddingServiceAreaName;
    public  $bidCompanyAreasName;
    public  $isWriteComplete;
    public  $contactsType;

    /*
        public  function getDeveloperId(){
            return $this->developerUid;
        }
    */


    private static $stateList = [
        self::BIDDING_REGISTERING  => 'registering',   // 报名中
        self::BIDDING_REGISTER_END => 'registerend',   // 报名结束
        self::BIDDING_PRE_QUALIFY  => 'finalist',      // 完成资格预审
        self::BIDDING_SEND         => 'sendbid',       // 已发标
        self::BIDDING_RETURN       => 'returnbid',     // 回标
        self::BIDDING_DISCUSS      => 'evaluatebid',   // 评标
        self::BIDDING_WIN          => 'winbid'         // 定标
    ];


    /**
     * 根据招标状态获取招标状态标识
     * @param $state
     * @return mixed|string
     */
    public static function getStateTag($state)
    {
        if (!isset(static::$stateList[$state])) {
            return '';
        }
        return static::$stateList[$state];
    }


    /**
     * 根据招标状态 获取已经完成的招标状态标签
     * @param $state
     * @return array|null
     */
    public static function getStateProcessTag($state)
    {
        if (!isset(static::$stateList[$state])) {
            return null;
        }

        $result = [];
        foreach (static::$stateList as $key => $value) {

            $result[] = $value;
            if ($key == $state) {
                return $result;
            }

        }

    }


}
